﻿<!DOCTYPE HTML>
<html>
<head>
    {include file="common:meta"}
    <style>
        .export-btn{
            margin: 15px 0 0;
        }
        .count-txt{
            text-align: center;
            font-size: 15px;
            font-weight: bold;
        }
        #countMoney{
            font-size: 15px;
            font-weight: bold;
            margin-left: 20px;
        }

    </style>
</head>
<body>
<div class="page-container">
    <div class="ibox-content" id="toolbar">
        <form action="" class="form-inline" id="form" data-url="">
            <div class="form-group">
                <label class="control-label">
                    <label class="control-label">开始时间：
                        <input type="text" class="form-control date-search" id="start_time" placeholder="">
                    </label>
                </label>
            </div>
            <div class="form-group">
                <label class="control-label">
                    <label class="control-label">结束时间：
                        <input type="text" class="form-control date-search" id="end_time" placeholder="">
                    </label>
                </label>
            </div>
            <div class="form-group">
                <label class="control-label" for="key">选项:</label>
                <select id="key" class="form-control" name="key">
                    <option value="receive_user_id">接受方ID</option>
                    <option value="send_user_id">付款方ID</option>
                    <option value="order_no">订单号</option>
                </select>
            </div>
            <div class="form-group">
                <label class="control-label" for="value">输入:</label>
                <input class="form-control" id="value" type="text" name="value">
            </div>
            <button type="button" class="btn btn-primary" id="eventQuery">查询</button>
            <button type="button" onclick="location.replace(location.href);" class="btn btn-success ">刷新</button>
            <!--<input type="text" class="form-control" id="countMoney" style="width:130px;"  value="" placeholder="查询充值总金额" disabled>-->
        </form>
        <div class="export-btn">
            <button class="btn btn-w-m btn-warning" id="export-btn">导出数据</button>
        </div>

    </div>
    <div class=" float-e-margins">
        <div class="ibox-content">
            <div class="tabs-container">
                <div class="count-txt">
                    <button class="count-charge  btn btn-w-m btn-warning" >总充值金额:</button>
                    <label class="control-label">
                        <label class="control-label">
                            <input type="text" class="form-control" id="count-charge" style="width:120px;"  value="" placeholder="总充值金额" disabled>
                        </label>
                    </label>
                    <button class="wx-count-charge btn btn-w-m btn-warning">微信充值总额:</button>
                    <label class="control-label">
                        <label class="control-label">
                            <input type="text" class="form-control" id="wx-count-charge" style="width:120px;"  value="" placeholder="总充值金额" disabled>
                        </label>
                    </label>
                    <button class="alipay-count-charge btn btn-w-m btn-warning" >支付宝充值总额:</button>
                    <label class="control-label">
                        <label class="control-label">
                            <input type="text" class="form-control" id="alipay-count-charge" style="width:120px;"  value="" placeholder="总充值金额" disabled>
                        </label>
                    </label>
                    <button class="remain-count-charge btn btn-w-m btn-warning" >剩余金额:</button>
                    <label class="control-label">
                        <label class="control-label">
                            <input type="text" class="form-control" id="remain-count-charge" style="width:120px;"  value="" placeholder="除去成功提现" disabled>
                        </label>
                    </label>
                    <button class="today-count-charge  btn btn-w-m btn-warning" >今日充值金额:</button>
                    <label class="control-label">
                        <label class="control-label">
                            <input type="text" class="form-control" id="today-count-charge" style="width:120px;"  value="" placeholder="" disabled>
                        </label>
                    </label>
                </div>
                <div class="tab-content">
                    <div class=" tab-pane active" id="tab-1">
                        <table id="tb_departments"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="common:footer"}
<script>
    $(document).ready(function () {
        initTable();
        // getCountData();
    });

    function initTable() {
        $('#tb_departments').bootstrapTable({
            url: '/RechargeIndexData',         //请求后台的URL（*）
            dataField: 'data',
            method: 'get',                      //请求方式（*）
            striped: true,                      //是否显示行间隔色
            cache: true,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            pagination: true,                   //是否显示分页（*）
            queryParams: queryParams,//传递参数（*）
            showToggle: true,
            showRefresh: true,
            sidePagination: 'server',           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            pageSize: 25,                       //每页的记录行数（*）
            pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
            showColumns: true,                  //是否显示所有的列
            showPaginationSwitch: true,
            minimumCountColumns: 2,             //最少允许的列数
            toolbar: '#toolbar',
            columns: [ {
                field: 'u_id',
                title: '接收方ID',
            }, {
                field: 'user_nickname',
                title: '接收方用户名',
            }, {
                field: 'send_user_uid',
                title: '付款方ID',
            },{
                field: 'send_user_nickname',
                title: '付款方用户名'
            }, {
                field: 'amount',
                title: '充值金额'
            }, {
                field: 'state',
                title: '充值方式',
            }, {
                field: 'order_no',
                title: '订单号',
            }, {
                field: 'diamonds',
                title: '钻石',
            }, {
                field: 'gold',
                title: '金币',
            },{
                field: 'type',
                title: '类型',
                formatter:function (value, row, index) {
                    var arr = [];
                    arr[0] = '系统默认'; arr[1]='新年活动充值'; arr[2]='已被修正';
                    return arr[row.type] ? arr[row.type] : '未知';
                }
            }, {
                field: 'create_time',
                title: '充值时间',
            },{
                field: 'Button',
                title: '操作',
                events: operateEvents,
                formatter: operateFormatter
            }]
        });
    }

    //得到查询的参数

    function queryParams(params) {
        params.pageNum = params.offset / params.limit + 1;
        params.key = $('#key').val();
        params.value = $('#value').val();
        params.start_time = $('#start_time').val();
        params.end_time = $('#end_time').val();
        $('#export-btn').attr('map',JSON.stringify(params));
        return params;
    }

    // 搜索按钮触发事件
    $(function () {
        $("#eventQuery").click(function () {
            $('#tb_departments').bootstrapTable(('refresh'));	// 很重要的一步，刷新url！
            //getCountData();
        });

    });
    //时间搜索插件
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        lay('.date-search').each(function () {
            laydate.render({
                elem: this,
                type: 'datetime',
                trigger: 'click'
            });
        });
    });
    //操作
    function operateFormatter(value, row, index){

        if(row.type === 2)
            var sho = 'none';
        else
            var sho = 'inline-block';

        return [
            '<button type="button"  class="userInfo-btn btn btn-info  btn-sm" style="margin-right:15px;">查看用户信息</button>',
            '<button type="button"  class="edit-btn btn btn-danger  btn-sm" style="margin-right:15px; display: '+sho+';">修改</button>'
        ].join('');
    }
    window.operateEvents = {
        'click .userInfo-btn':function(e,value,row,index){
            layer.open({
                type: 2,
                title: ['用户信息','font-size:18px;font-family:楷体;font-weight:700;'],
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['900px', '600px'],
                content:"/UserInfo?user_id=" + row.user_id,
                offset:'auto',
                scrollbar:false
            });
        },
        'click .edit-btn':function(e,value,row,index){
            layer.open({
                type: 2,
                title: ['修改充值信息','font-size:18px;font-family:楷体;font-weight:700;'],
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['900px', '600px'],
                content:"/RechargeEdit?order_no=" + row.order_no,
                offset:'auto',
                scrollbar:false,
                end: function () {
                    $('#tb_departments').bootstrapTable(('refresh'));	// 很重要的一步，刷新url！
                }
            });
        }
    };

    //导出数据到excel表
    $('#export-btn').click(function(){
        var map = JSON.parse($(this).attr('map'));
        var filterKeyArr = ['pageNum','limit','offset','order'];

        for(var key in map){
            if(filterKeyArr.indexOf(key) != -1)
                delete map[key];
        }
        location.href = '/RechargeDataExport?uid=' +$('#uid').val()+ '&start_time=' +$('#start_time').val()
            + '&end_time=' +$('#end_time').val();
    });
    //获取查询总金额
    function getCountData(){
        var startTime = $('#start_time').val(),endTime = $('#end_time').val(),uid = $('#uid').val(),datas = {};
        uid = trimStr(uid);
        if(startTime.length)
            datas.start_time = startTime;
        if(endTime.length)
            datas.end_time = endTime;
        if(uid.length)
            datas.uid = uid;
        $.ajax({
            type:'get',
            url:'/RechargeCountData',
            data:datas,
            dataType:'json',
            success:function(result){
                // console.log(result);
                $('#countMoney').val('￥'+result);
            },
            error:function(err){
                layer.msg('服务器开小差了！',{
                    time:2000
                });
            }
        });
    }

    $('.count-charge').click(function(){
        var param = 1;
        //将对象传给函数，在这里不能用this,this代表的是button标签
        var obj = $('#count-charge');
        countRecharge(param,obj);
    });
    $('.wx-count-charge').click(function(){
        var param = 2;
        var obj = $('#wx-count-charge');
        countRecharge(param,obj);
    });
    $('.alipay-count-charge').click(function(){
        var param = 3;
        var obj = $('#alipay-count-charge');
        countRecharge(param,obj);
    });
    $('.remain-count-charge').click(function(){
        var param = 4;
        var obj = $('#remain-count-charge');
        countRecharge(param,obj);
    });
    $('.today-count-charge').click(function(){
        var param = 5;
        var obj = $('#today-count-charge');
        countRecharge(param,obj);
    });
    //计算充值
    function countRecharge(param,obj){
        var startTime = $('#start_time').val(),endTime = $('#end_time').val(),uid = $('#uid').val(),datas = {};
       // uid = trimStr(uid);
        if(startTime.length)
            datas.start_time = startTime;
        if(endTime.length)
            datas.end_time = endTime;
            datas.uid = uid;
        datas.type = param;
        $.ajax({
            type: "get",
            url: "/RechargeCount",
            data:datas,
            dataType: 'JSON',
            success: function (re) {
                if (re.code === 100) {
                    console.log(re.data);
                    // $('.'+obj).siblings('label').find('input').val(re.data);
                    obj.val('￥'+re.data);
                } else {
                    layer.msg('请重新查询，可能没有权限',{
                        icon:2,
                        time:1000
                    });
                }
            },
            error: function () {
                layer.msg('服务器开小差了',{
                    icon:2,
                    time:1000
                });
            }
        });
    }
</script>
</body>
</html>